package pkg.tenproject.gest.mail;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;

/**
 *
 * @author delmastro
 */
public class SendMail {
 public synchronized static boolean sendMail(String subject,String text){
       String[] to={"montedeicorvi@gmail.com"};
                String[] cc={"montedeicorvi@gmail.com"};
                String[] bcc={"montedeicorvi@gmail.com"};
                Properties props = new Properties();
                //Properties props=System.getProperties();
        props.put("mail.smtp.user", "montedeicorvi@gmail.com");
        props.put("mail.smtp.host", "smtp.gmail.com");
                if(!"".equals("465"))
        props.put("mail.smtp.port", "465");
                if(!"".equals("true"))
        props.put("mail.smtp.starttls.enable","true");
        props.put("mail.smtp.auth", "true");
                if(true){
                props.put("mail.smtp.debug", "true");
                }else{
                props.put("mail.smtp.debug", "false");
                }
                if(!"".equals("465"))
        props.put("mail.smtp.socketFactory.port", "465");
                if(!"".equals("javax.net.ssl.SSLSocketFactory"))
        props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
                if(!"".equals("false"))
        props.put("mail.smtp.socketFactory.fallback", "false");

        try
        {
                        Session session = Session.getDefaultInstance(props, null);
            session.setDebug(true);
            MimeMessage msg = new MimeMessage(session);
            msg.setText(text);
            msg.setSubject(subject);
            msg.setFrom(new InternetAddress("noreply@catyshop.com"));
                        for(int i=0;i<to.length;i++){
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to[i]));
                        }
                        for(int i=0;i<cc.length;i++){
            msg.addRecipient(Message.RecipientType.CC, new InternetAddress(cc[i]));
                        }
                        for(int i=0;i<bcc.length;i++){
            msg.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[i]));
                        }
            msg.saveChanges();
                        Transport transport = session.getTransport("smtp");
                        transport.connect("smtp.gmail.com", "montedeicorvi@gmail.com", "log2=1");
                        transport.sendMessage(msg, msg.getAllRecipients());
                        transport.close();
                        // JOptionPane.showMessageDialog(null, "OK MAIL");
                        return true;
        }
        catch (Exception mex)
        {
            mex.printStackTrace();
                        return false;
        }
        }
}
